﻿using System;
namespace SLS.ExClassLib.Events
{
    /// <summary>
    /// Define the message event type and also the log level
    /// </summary>
    public enum MessageEventType
    {
        /// <summary>
        /// Highest
        /// </summary>
        OFF = 0,
        /// <summary>
        /// FATAL
        /// </summary>
        FATAL = 1,
        /// <summary>
        /// ERROR
        /// </summary>
        ERROR = 2,
        /// <summary>
        /// WARN
        /// </summary>
        WARN = 3,
        /// <summary>
        /// INFO
        /// </summary>
        INFO = 4,
        /// <summary>
        /// DEBUG
        /// </summary>
        DEBUG = 5,
        /// <summary>
        /// Verbose
        /// </summary>
        VERBOSE = 6,
        /// <summary>
        /// Lowest
        /// </summary>
        ALL = 9
    }

    /// <summary>
    /// Classe used to store message information which are mapped to the log grid
    /// </summary>
    public class MessageInfo
    {
        #region =================PROPERTIES=================

        private MessageEventType _Type = MessageEventType.INFO;
        /// <summary>
        /// Type of message = the log level
        /// </summary>
        public MessageEventType Type
        {
            get { return _Type; }
            set { _Type = value; }
        }

        private DateTime _When = DateTime.Now;
        /// <summary>
        /// When does this event occurs
        /// </summary>
        public DateTime When
        {
            get { return _When; }
            set { _When = value; }
        }

        private string _Where;
        /// <summary>
        /// Where it occurs in the code, only used by trace event in verbose mode
        /// </summary>
        public string Where
        {
            get { return _Where; }
            set { _Where = value; }
        }
        private string _Details;
        /// <summary>
        /// Contains details about the event
        /// </summary>
        public string Details
        {
            get { return _Details; }
            set { _Details = value; }
        }
        #endregion

        #region =================CONSTRUCTORS=================

        /// <summary>
        /// Constructor
        /// </summary>
        public MessageInfo()
        {
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="typ"></param>
        /// <param name="where"></param>
        /// <param name="details"></param>
        public MessageInfo(MessageEventType typ, string where, string details)
        {
            _Type = typ;
            _Where = where;
            _Details = details;
        }
        #endregion

        #region =================OVERRIDES=================

        /// <summary>
        /// override the method for use in the trace methods
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            string result = "";
            switch (_Type)
            {
                case MessageEventType.ERROR:
                    result = string.Format("ERROR: {0}; into:{1}; details:{2};", _When, _Where, _Details);
                    break;
                case MessageEventType.WARN:
                    result = string.Format("WARN: {0}; into:{1}; details:{2};", _When, _Where, _Details);
                    break;
                case MessageEventType.DEBUG:
                    result = string.Format("DEBUG: {0}; into:{1}; details:{2};", _When, _Where, _Details);
                    break;
                case MessageEventType.INFO:
                    result = string.Format("INFO: {0}; into:{1}; details:{2};", _When, _Where, _Details);
                    break;
                case MessageEventType.VERBOSE:
                    result = string.Format("INFO: {0}; into:{1}; details:{2};", _When, _Where, _Details);
                    break; 
                default:
                    result = string.Empty;
                    break;
            }
            return result;
        }

        #endregion
    }
}
